from  students.models import Students

from rest_framework import serializers
from rest_framework.validators import UniqueValidator

class StudentsSerializers(serializers.ModelSerializer):
    # name = serializers.CharField(max_length=12,min_length=2,error_messages={
    #     'max_length':'最长不能超过12位',
    #     'min_length':'最短不能低于2位',
    #     'required': '姓名必填'
    # })
    # school = serializers.CharField(max_length=32,min_length=2,error_messages={
    #     'max_length': '最长不能超过32位',
    #     'min_length': '最短不能低于2位',
    #     'required': '学校必填'
    # })
    # grade = serializers.CharField(max_length=6,min_length=2,error_messages={
    #     'max_length': '最长不能超过32位',
    #     'min_length': '最短不能低于2位',
    #     'required': '年级必填'
    # })
    # the_class = serializers.CharField(max_length=3,min_length=1,error_messages={
    #     'max_length': '最长不能超过3位',
    #     'min_length': '最短不能低于1位',
    #     'required': '班级必填'
    # })

    student_id = serializers.CharField(max_length=18,min_length=6,validators=[UniqueValidator(queryset=Students.objects.all())],error_messages={
        'max_length': '最长不能超过18位',
        'min_length': '最短不能低于6位',
        'required': '学号必填',
        'validators':'用户名不存在'
    })

    id_number = serializers.CharField(max_length=18,min_length=18,error_messages={
        'max_length': '最长不能超过18位',
        'min_length': '身份证长度不够',
        'required': '身份证必填'
    })
    class Meta:
        model = Students
        fields = ('student_id','id_number')

